<?php
require '../../config.php';
$filtro=$_REQUEST['filtro'];
$query= "select * from hossbd.clientesventas where nombre LIKE '%".$filtro."%' OR contacto LIKE '%".$filtro."%'";
$resultset = mysql_query($query,$conexion);

if(!$resultset)
{
    mysql_close();
   echo "<legend>Sin Resultados</legend>";
}
elseif(!mysql_num_rows($resultset))
{
    mysql_close();
   echo "<legend>Sin Resultados</legend>";
}
else
{
		
			
			echo   "<table class='table table-bordered'>";
			echo   "<caption>Reporte en pantalla</caption>";
			echo   "<tr>";
			echo   "<th>Identificador</th><th>Nombre</th><th>Direcci&oacute;n</th><th>Tel&eacute;fono</th><th>Contacto</th><th>Tel. contacto</th><th>Cargo contacto</th><th>Email contacto</th><th>Tipo Cliente</th><th>Opciones</th>";
			echo   "</tr>";
			echo   "<tbody>";
			$aux=0;
			while($row = mysql_fetch_assoc($resultset))
			{
				if($aux==0){
					$color="#FFFFFF";
					$aux=1;
				}else{
					$color="#F9F9F9";
					$aux=0;
				}
				echo ("<tr bgcolor='".$color."'>");
				echo   "<td>".$row['idclientesventas']."</td>";
				echo   "<td>"._convert($row['nombre'])."</td>";
				echo   "<td>"._convert($row['direccion'])."</td>";
				echo   "<td>".$row['telefono']."</td>";
				echo   "<td>"._convert($row['contacto'])."</td>";
				echo   "<td>".$row['telcontacto']."</td>";
				echo   "<td>"._convert($row['cargo'])."</td>";
				echo   "<td>"._convert($row['email'])."</td>";
				if($row['tipo']==1)$tipo="Prospecto";
				if($row['tipo']==2)$tipo="Potencial";
				if($row['tipo']==3)$tipo="Activo";
				echo   "<td>".$tipo."</td>";
				echo   "<td><input type = button class='btn btn-info btn-xs'  value= Modificar onclick='modificar(". $row['idclientesventas'] .")'>&nbsp;<input type = button class='btn btn-danger btn-xs' value= Eliminar onclick='eliminar(". $row['idclientesventas'] .")'></td>";
				echo   "</tr>";
			}
			echo   "</tbody>";
			echo   "</table>";
			mysql_close();
		
}
function _convert($content) {
	if(!mb_check_encoding($content, 'UTF-8')
	OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {

		$content = mb_convert_encoding($content, 'UTF-8');

		if (mb_check_encoding($content, 'UTF-8')) {
			// log('Converted to UTF-8');
		} else {
			// log('Could not converted to UTF-8');
		}
	}
	return $content;
}
?>